﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;

namespace EcoSystem.EntityFrameworkCore
{
    public class BaseEfCoreEntityExtensionMappings
    {
        private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

        public static void Configure()
        {
            OneTimeRunner.Run(() =>
            {
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.OpenId), (e, p) => p.HasMaxLength(128).HasDefaultValue("").IsRequired());
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Gender), (e, p) => p.HasMaxLength(4));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, Nullable<DateTime>>(nameof(SystemUser.Brithday), (e, p) => p.IsRequired(false));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.PersonnelIndustry), (e, p) => p.HasMaxLength(64));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Education), (e, p) => p.HasMaxLength(64));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.PersonalSignature), (e, p) => p.HasMaxLength(256));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Introduction), (e, p) => p.HasMaxLength(512));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Avatar), (e, p) => p.HasMaxLength(256));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.CardNumber), (e, p) => p.HasMaxLength(32));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, AccountType>(nameof(SystemUser.AccountType), (e, p) => p.HasDefaultValue(AccountType.AdminUser).IsRequired());
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.NativePlace), (e, p) => p.HasMaxLength(64));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Nation), (e, p) => p.HasMaxLength(32));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.Address), (e, p) => p.HasMaxLength(128));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.RegionCode), (e, p) => p.HasMaxLength(32));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.OrganizeId), (e, p) => p.HasMaxLength(128));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, string>(nameof(SystemUser.OrganizeCode), (e, p) => p.HasMaxLength(128));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, bool>(nameof(SystemUser.IsStatic), (e, p) => p.HasDefaultValue(false));
                ObjectExtensionManager.Instance.MapEfCoreProperty<IdentityUser, Nullable<Guid>>(nameof(SystemUser.EnterpriseId), (e, p) => p.IsRequired(false));
            });
        }
    }
}
